<?php

class test1{
      public $name;
      public $test2=11;
    public function __construct($name)
    {
         $this->name=$name;
    }
    public function test1(){
        return 123;
    }
    public function test2(){
        return 456;
    }
}

class test
{
    public $obj;

    public function __construct($obj)
    {
        $this->obj=$obj;
    }

    public function test()
    {
        $name=$this->obj->name;
       echo $this->obj->{$name};
    }
}

$test=new test( new test1('test2'));
$test->test();